"""添加users表

Revision ID: dd0648b0f354
Revises: e850c5a37d99
Create Date: 2025-11-17 16:17:37.028815

"""

from typing import Sequence, Union

import sqlalchemy as sa
import sqlmodel
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "dd0648b0f354"
down_revision: Union[str, Sequence[str], None] = "e850c5a37d99"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "users",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("create_time", sa.DateTime(), server_default=sa.text("now()"), nullable=True, comment="创建时间"),
        sa.Column("update_time", sa.DateTime(), server_default=sa.text("now()"), nullable=True, comment="更新时间"),
        sa.Column("user_no", sqlmodel.sql.sqltypes.AutoString(length=10), nullable=False, comment="编号"),
        sa.Column("password", sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False, comment="密码"),
        sa.Column("user_name", sqlmodel.sql.sqltypes.AutoString(length=50), nullable=False, comment="用户名"),
        sa.Column("nick_name", sqlmodel.sql.sqltypes.AutoString(length=50), nullable=False, comment="昵称"),
        sa.Column(
            "user_gender",
            sa.Enum("M", "F", name="genderenum"),
            server_default="M",
            nullable=True,
            comment="性别: M-男, F-女",
        ),
        sa.Column("user_email", sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False, comment="邮箱"),
        sa.Column("user_phone", sqlmodel.sql.sqltypes.AutoString(length=20), nullable=False, comment="手机号"),
        sa.Column(
            "status",
            sa.Enum("Y", "N", name="userstatusenum"),
            server_default="Y",
            nullable=True,
            comment="状态: Y-激活, N-禁用",
        ),
        sa.Column("last_login", sa.DateTime(), nullable=True, comment="最后登录时间"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("nick_name"),
        sa.UniqueConstraint("user_phone"),
        comment="用户表",
    )
    op.create_index(op.f("ix_users_user_email"), "users", ["user_email"], unique=True)
    op.create_index(op.f("ix_users_user_name"), "users", ["user_name"], unique=False)
    op.create_index(op.f("ix_users_user_no"), "users", ["user_no"], unique=True)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_users_user_no"), table_name="users")
    op.drop_index(op.f("ix_users_user_name"), table_name="users")
    op.drop_index(op.f("ix_users_user_email"), table_name="users")
    op.drop_table("users")
    # ### end Alembic commands ###
